// 在UIO中，点击接收三角形接收消息
_dss_editor._canvas._operation.uioOp.fire = function(eventObj) {
	try {
		switch (eventObj.eventType) {
			case MOUSE_L_DOWN:
				break;
			case MOUSE_R_DOWN:
				break;
			case MOUSE_UP:
				break;
			case MOUSE_MOVE:
				this.handleMouseMove(eventObj);
				break;
			case MOUSE_DBCLICK:
				break;
			case MOUSE_CLICK:
				this.handleMouseClick(eventObj);
				break;
			case MOUSE_ONCONTEXTMENU:
				break;
			default:
				break;
		}
	} catch (exc) {
		console.error(exc.stack);
	}
};
_dss_editor._canvas._operation.uioOp.handleMouseMove = function(eventObj) {
	var canvas = eventObj.canvas;
	if (!paletteViewer.selectionItem.type && canvas.onDiagram.style != POINT && canvas.mousePosition == SPACE) {
		var flag = this.inDeriveFlag(canvas, eventObj.location);
		if (flag) {
			canvas.entity.style.cursor = 'pointer';
		}
	}
};

_dss_editor._canvas._operation.uioOp.handleMouseClick = function(eventObj) {
	var canvas = eventObj.canvas;
	if (!paletteViewer.selectionItem.type && canvas.onDiagram.style != POINT && canvas.mousePosition == SPACE) {
		var flag = this.inDeriveFlag(canvas, eventObj.location);
		switch (flag) {
			case SEND_MSG:
				this.sendMsg(canvas);
				break;
			case RECEIVE_MSG:
				this.recevieMsg(canvas);
				break;
			default:
				break;
		}
	}
};
_dss_editor._canvas._operation.uioOp.recevieMsg = function(canvas) {
	var system = canvas.selectionDiagrams[0];
	new RemoveCommand(canvas, system.parent, system).doCommand();
	if (ArrayTool.isArrayInstance(system)) {
		var array = system.parent;
		// array.removeInstance(system);
		if (array.subInstance.length == 1) {
			var sys = array.subInstance[0];
			sys.setHasShadow(NO);
			delete sys.index;
			sys.showInfo.rectangle.x = 30;
			sys.showInfo.rectangle.y = 30;
			array.parent.addChild(sys);

			//array.subInstance = [];
			array.parent.removeChild(array);
		}
	} else {
		try {
			$('#array' + canvas.entity.id).window('close');
		} catch(e) {
			console.error(e);
		}

	}
	canvas.removeSelectionSystem();
	canvas.update();
};

// 在UIO中，点击发送三角形进行发送消息
_dss_editor._canvas._operation.uioOp.sendMsg = function(canvas) {
	//console.log(_dss_editor._toolkit.stringifyToSendMessage(canvas));
	_dss_editor.ws.send(_dss_editor._toolkit.stringifyToSendMessage(canvas));
	canvas.selectionDiagrams.splice(0, canvas.selectionDiagrams.length);
};

_dss_editor._canvas._operation.uioOp.inDeriveFlag = function(canvas) {
	var diagram = canvas.onDiagram;
	if (diagram.hasOwnProperty("offset")) {
		if (diagram.getDeriveFlag() == SENDER) {
			if (diagram.isShowContent()) {
				if (diagram.offset.y > labelHeight && diagram.offset.x > diagram.showInfo.rectangle.w - deriveOffset && diagram.offset.x < diagram.showInfo.rectangle.w) {
					return SEND_MSG;
				}
			} else {
				if (diagram.offset.x > diagram.getRectangle().w - deriveOffset && diagram.offset.x < diagram.getRectangle().w) {
					return SEND_MSG;
				}
			}
		} else if (diagram.getDeriveFlag() == RECEIVER) {
			if (diagram.isShowContent()) {
				if (diagram.offset.y > labelHeight && diagram.offset.x > 0 && diagram.offset.x < deriveOffset) {
					return RECEIVE_MSG;
				}
			} else {
				if (diagram.offset.x < deriveOffset) {
					return RECEIVE_MSG;
				}
			}
		}
	}
	return SPACE;
};
